package org.room402.entity.chat;

import cn.hutool.core.collection.ConcurrentHashSet;
import lombok.Builder;
import lombok.Data;
import org.room402.model.chat.UserInfoView;

@Data
@Builder
public class ChatPool {
    private String id;
    /**
     * 创建者ID
     */
    private String creatorId;
    private String name;
    private String avatarUrl;

    /**
     * 聊天池用户
     */
    private ConcurrentHashSet<UserInfoView> members;

    public static ChatPool form(UserSession userSession, String name, String id) {
        return ChatPool.builder()
                .id(id)
                .creatorId(userSession.getId())
                .name(name)
                .members(new ConcurrentHashSet<>())
                .build();
    }

    public void add(UserSession userSession) {
        members.add(UserInfoView.form(userSession));
    }
}
